$(function () {
    var contentEditor = editormd("md-content", {
        width: "100%",
        height: 640,
        syncScrolling: "single",
        path: CONTEXT_PATH+"/lib/editormd/lib/",
        toolbarIcons : function() {
            return ["undo","redo","|",
                "bold","del","italic","quote","ucwords","uppercase","lowercase","|",
                 "h1","h2","h3","h4","h5","h6","|",
                "list-ul","list-ol","hr","|",
                "link","reference-link","image","code","preformatted-text",
                "code-block","table","datetime","html-entities","pagebreak","|",
                "goto-line","watch","preview","clear","search","|",
                "help","info",
                "releaseIcon", "index"]
        }
    });
});
function draft() {
    if (!checkout()){
        alert("帖子标题或内容不能为空");
        return;
    }
    $.post(
        CONTEXT_PATH+'/discuss/draft',
        {"id":$("input[name='id']").val(),"title":$("input[name='title']").val(),"content":$("textarea[name='content']").text()},
        function (data) {
            data=$.parseJSON(data);
            alert(data.msg);
        }
    );
}
function issue() {
    if (!checkout()){
        alert("帖子标题或内容不能为空");
        return;
    }
    $.post(
        CONTEXT_PATH+'/discuss/addOrUpdate',
        {"id":$("input[name='id']").val(),"title":$("input[name='title']").val(),"content":$("textarea[name='content']").text()},
        function (data) {
            data=$.parseJSON(data);
            alert(data.msg);
            if (data.code==0){
                setTimeout(function () {
                    location.href=CONTEXT_PATH+'/index';
                },1000);
            }
        }
    );
}

function checkout() {
    var title = $("input[name='title']").val();
    var content = $("textarea[name='content']").text();
    var reg=/^\s*$/;
    var titleCheckout = title==null||title==undefined||reg.test(title);
    var contentCheckout = content==null||content==undefined||reg.test(content);
    if (titleCheckout||contentCheckout){
        return false;
    }
    return true;
}